<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<table class="table">

    <tr>
        <th>ID</th>
        <th>商品名称</th>
        <th>商品编号</th>
        <th>商品分类</th>
        <th>商品品牌</th>
        <th>商品库存</th>
        <th>商品价格</th>
        <th>商品图片</th>
        <th>上架</th>
        <th>精品</th>
        <th>新品</th>
        <th>热销</th>

        <th>操作</th>
    </tr>


    {foreach $data as $k=>$v}
    <tr class="success">
        <td>{$v.id}</td>
        <td>{$v.good_name}</td>
        <td>{$v.good_id}</td>
        <td>{$v.good_type}</td>
        <td>{$v.good_brand}</td>
        <td>{$v.good_stock}</td>
        <td>{$v.good_price}</td>
        <td>
            <img src="{$v.good_img}" alt="" width="66px" height="66px">
        </td>
        <td>
            {if $v.g_way == 1}
            <a href="#">✔</a>
            {/if}
            {if $v.g_way == 2}
            <a href="#">✘</a>
            {/if}
        </td>
        <td>
            {if $v.g_cacy == 1}
            <a href="#">✔</a>
            {/if}
            {if $v.g_cacy == 2}
            <a href="#">✘</a>
            {/if}
        </td>
        <td>
            {if $v.news == 1}
            <a href="#">✔</a>
            {/if}
            {if $v.news == 2}
            <a href="#">✘</a>
            {/if}
        </td>
        <td>
            {if $v.bests == 1}
            <a class="bests{$v.id}" name="1" onclick="bests({$v.id},this)" href="#">✔</a>
            {/if}
            {if $v.bests == 2}
            <a class="bests{$v.id}" name="2" onclick="bests({$v.id},this)" href="#">✘</a>
            {/if}
        </td>
        <td>
            <a href="javascript:void(0);"> 编辑 </a>
            <a href="javascript:void(0);" onclick="if(confirm('确认删除？')) location.href='#'"> 删除 </a>
        </td>
    </tr>
    {/foreach}

</table>
{$data->render()}
<script>
    //更改状态 1 为是 2为否
    function bests(id, a) {
        var name = a.getAttribute('name');
        var text = $('.bests' + id).text()
        alert(text);

        if (name == 1) {
            name = 2
            text = '✘'
        } else {
            name = 1
            text = '✔'
        }
        $.ajax({
            'url': "http://www.admin.com/exam/exam/update",
            'type': 'post',
            'data': {
                'id': id,
                'news': name
            },
            dataType: 'json',
            success: function (e) {
                console.log(e)
               if (e.status==200){
                   $('.bests' + id).text(text)
                   a.setAttribute('name',name);
                   console.log(e)
               }
            }
        })
    }
</script>